home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 626-650 / 644 / fontconverter / source / fc_v1.3.c < prev    next >
C/C++ Source or Header  |  1995-03-15  |  7KB  |  207 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*                         FontConverter V1.3                           */
  4. /*                                                                      */
  5. /*                         Freeware © 1992 by                           */
  6. /*                                                                      */
  7. /*                            Andreas Baum                              */
  8. /*                        Eugen-Roth-Straße 25                          */
  9. /*                           W-8430 Neumarkt                            */
  10. /*                               Germany                                */
  11. /*                                                                      */
  12. /*                      Convert Fonts in C-Source                       */
  13. /*                                                                      */
  14. /*    Usage: FontConverter_V1.3 <Fontname> <Fontheight> <Outputfile>    */
  15. /*                                                                      */
  16. /*                            Needs >= OS1.2                            */
  17. /*                                                                      */
  18. /*                            Compiler: DICE                            */
  19. /*                                                                      */
  20. /*           Compilerusage: DCC -oFontConverter_V1.3 FC_V1.3.c          */
  21. /*                                                                      */
  22. /************************************************************************/
  23.  
  24.  
  25. #include <libraries/dos.h>
  26.  
  27. UWORD YSize, XSize, Baseline, BoldSmear, Accessors, Modulo;
  28. UWORD Dat_Value;
  29.  
  30. ULONG Font, CharData, CharLoc, CharSpace, CharKern;
  31. ULONG In_Datei, Out_Datei;
  32. ULONG Dat_Length, x, y;
  33.  
  34. UBYTE Style, Flags, LoChar, HiChar;
  35. UBYTE Font_Name[50], Out_Path[100], In_Path[100], Data[100];
  36.  
  37. main(argc, argv)
  38. LONG argc;
  39. BYTE **argv;
  40.   {
  41.     if(argc != 4)
  42.       {
  43.         printf("\033[1mUsage: FontConverter_V1.3 <Fontname> <Fontheight> <Outputfile>\033[0m\n");
  44.         close_all();
  45.       }
  46.  
  47.     sprintf(In_Path,"Fonts:%s/%s",argv[1],argv[2]);
  48.     sprintf(Font_Name,"%s%s",argv[1],argv[2]);
  49.     sprintf(Out_Path,"%s",argv[3]);
  50.  
  51.     printf("\n\033[1m\033[33mFontConverter_V1.3\033[0m\n\n");
  52.     printf("© 1992 by Baum Andreas\n\n");
  53.  
  54.     if(!(In_Datei=Open(In_Path,MODE_OLDFILE)))
  55.       {
  56.         printf("\033[1mERROR: Can't find Font  \033[3m%s \033[0m\033[1m!\033[0m\n\n",In_Path);
  57.         close_all();
  58.       }
  59.  
  60.     Seek(In_Datei,48,OFFSET_BEGINNING);
  61.     Read(In_Datei,&Font,4);
  62.     if(Font!=0x1a0f80)
  63.       {
  64.         printf("\033[1mError: No Font or packed Font or inadmissible Font !\033[0m\n\n");
  65.         close_all();
  66.       }
  67.  
  68.     if(!(Out_Datei=Open(Out_Path,MODE_NEWFILE)))
  69.       {
  70.         printf("\033[1mError: Can't install Outputfile  \033[3m%s \033[0m\033[1m!\033[0m\n\n",Out_Path);
  71.         close_all();
  72.       }
  73.  
  74.     printf("\033[3mWorking so hard ... Please Wait\033[0m\n\n");
  75.  
  76.     Seek(In_Datei,110,OFFSET_BEGINNING);
  77.     Read(In_Datei,&YSize,2);
  78.     Read(In_Datei,&Style,1);
  79.     Read(In_Datei,&Flags,1);
  80.     Read(In_Datei,&XSize,2);
  81.     Read(In_Datei,&Baseline,2);
  82.     Read(In_Datei,&BoldSmear,2);
  83.     Read(In_Datei,&Accessors,2);
  84.     Read(In_Datei,&LoChar,1);
  85.     Read(In_Datei,&HiChar,1);
  86.     Read(In_Datei,&CharData,4);
  87.     Read(In_Datei,&Modulo,2);
  88.     Read(In_Datei,&CharLoc,4);
  89.     Read(In_Datei,&CharSpace,4);
  90.     Read(In_Datei,&CharKern,4);
  91.  
  92.     Dat_Length=(Modulo*YSize+(HiChar-LoChar+2)*4)/2;
  93.     if(CharSpace!=0)
  94.       Dat_Length=Dat_Length+(HiChar-LoChar+2);
  95.     if(CharKern!=0)
  96.       Dat_Length=Dat_Length+(HiChar-LoChar+2);
  97.  
  98.     sprintf(Data,"/*  FontConverter_V2.0 © 1992 by Andreas Baum  */\n\n");
  99.     Write(Out_Datei,Data,strlen(Data));
  100.  
  101.     sprintf(Data,"#include <graphics/text.h>\n\n");
  102.     Write(Out_Datei,Data,strlen(Data));
  103.  
  104.     sprintf(Data,"UWORD %sdump[] =\n",Font_Name);
  105.     Write(Out_Datei,Data,strlen(Data));
  106.  
  107.     sprintf(Data,"  {\n");
  108.     Write(Out_Datei,Data,strlen(Data));
  109.  
  110.     y=1;
  111.     for(x=0;x<Dat_Length;x++)
  112.       {
  113.         Read(In_Datei,&Dat_Value,2);
  114.         if(x==Dat_Length-1)
  115.           {
  116.             sprintf(Data,"\t0x%04x\n",Dat_Value);
  117.             Write(Out_Datei,Data,strlen(Data));
  118.             y=9;
  119.           }
  120.         if(y<=7)
  121.           {
  122.             sprintf(Data,"\t0x%04x,",Dat_Value);
  123.             Write(Out_Datei,Data,strlen(Data));
  124.           }
  125.         if(y==8)
  126.           {
  127.             y=0;
  128.             sprintf(Data,"\t0x%04x,\n",Dat_Value);
  129.             Write(Out_Datei,Data,strlen(Data));
  130.           }
  131.         y++;
  132.       }
  133.  
  134.     sprintf(Data,"  };\n\n");
  135.     Write(Out_Datei,Data,strlen(Data));
  136.  
  137.     sprintf(Data,"struct TextFont %sFont;\n\n",Font_Name);
  138.     Write(Out_Datei,Data,strlen(Data));
  139.  
  140.     sprintf(Data,"FontInit_%s()\n",Font_Name);
  141.     Write(Out_Datei,Data,strlen(Data));
  142.  
  143.     sprintf(Data,"  {\n");
  144.     Write(Out_Datei,Data,strlen(Data));
  145.  
  146.     sprintf(Data,"    %sFont.tf_Message.mn_Node.ln_Name = \"%s.font\";\n",Font_Name,Font_Name);
  147.     Write(Out_Datei,Data,strlen(Data));
  148.  
  149.     sprintf(Data,"    %sFont.tf_YSize = 0x%04x;\n",Font_Name,YSize);
  150.     Write(Out_Datei,Data,strlen(Data));
  151.  
  152.     sprintf(Data,"    %sFont.tf_Style = 0x%02x;\n",Font_Name,Style);
  153.     Write(Out_Datei,Data,strlen(Data));
  154.  
  155.     sprintf(Data,"    %sFont.tf_Flags = 0x%02x;\n",Font_Name,Flags);
  156.     Write(Out_Datei,Data,strlen(Data));
  157.  
  158.     sprintf(Data,"    %sFont.tf_XSize = 0x%04x;\n",Font_Name,XSize);
  159.     Write(Out_Datei,Data,strlen(Data));
  160.  
  161.     sprintf(Data,"    %sFont.tf_Baseline = 0x%04x;\n",Font_Name,Baseline);
  162.     Write(Out_Datei,Data,strlen(Data));
  163.  
  164.     sprintf(Data,"    %sFont.tf_BoldSmear = 0x%04x;\n",Font_Name,BoldSmear);
  165.     Write(Out_Datei,Data,strlen(Data));
  166.  
  167.     sprintf(Data,"    %sFont.tf_Accessors = 0x%04x;\n",Font_Name,Accessors);
  168.     Write(Out_Datei,Data,strlen(Data));
  169.  
  170.     sprintf(Data,"    %sFont.tf_LoChar = 0x%02x;\n",Font_Name,LoChar);
  171.     Write(Out_Datei,Data,strlen(Data));
  172.  
  173.     sprintf(Data,"    %sFont.tf_HiChar = 0x%02x;\n",Font_Name,HiChar);
  174.     Write(Out_Datei,Data,strlen(Data));
  175.  
  176.     sprintf(Data,"    %sFont.tf_CharData = (APTR)((char *)&%sdump[0]+0x%08x);\n",Font_Name,Font_Name,CharData-110);
  177.     Write(Out_Datei,Data,strlen(Data));
  178.  
  179.     sprintf(Data,"    %sFont.tf_Modulo = 0x%04x;\n",Font_Name,Modulo);
  180.     Write(Out_Datei,Data,strlen(Data));
  181.  
  182.     sprintf(Data,"    %sFont.tf_CharLoc = (APTR)((char *)&%sdump[0]+0x%08x);\n",Font_Name,Font_Name,CharLoc-110);
  183.     Write(Out_Datei,Data,strlen(Data));
  184.  
  185.     sprintf(Data,"    %sFont.tf_CharSpace = (APTR)((char *)&%sdump[0]+0x%08x);\n",Font_Name,Font_Name,CharSpace-110);
  186.     if(CharKern == 0)
  187.       sprintf(Data,"    %sFont.tf_CharKern = 0x00000000;\n",Font_Name);
  188.     Write(Out_Datei,Data,strlen(Data));
  189.  
  190.     sprintf(Data,"    %sFont.tf_CharKern = (APTR)((char *)&%sdump[0]+0x%08x);\n",Font_Name,Font_Name,CharKern-110);
  191.     if(CharSpace == 0)
  192.       sprintf(Data,"    %sFont.tf_CharSpace = 0x00000000;\n",Font_Name);
  193.     Write(Out_Datei,Data,strlen(Data));
  194.  
  195.     sprintf(Data,"  }\n");
  196.     Write(Out_Datei,Data,strlen(Data));
  197.  
  198.     close_all();
  199.   }
  200.  
  201. close_all()
  202.   {
  203.     if(In_Datei) Close(In_Datei);
  204.     if(Out_Datei) Close(Out_Datei);
  205.     exit(0);
  206.   }
  207.